//此方法用于生成联系人树
function initContactPersonTree(boxid,appendstr){
		UserAction.getContactPersonTreeRootStr(
		function(data){
		 /*  root = {'text':'根','checked':'0','pid':'-1',children:[]}*/
			var str=" <script type=\"text\/javascript\">root={\'text\':\'所有联系人\',\'checked\':\'0\',\'pid\':\'-1\',children:\["+data+"\]}<\/script> ";
			 
			   $("body").append(str); //将变量追加到页面 
    				tree = new TreePanel({
					renderTo:boxid,
					'root' : root
				});
				tree.render();
				$("#"+boxid).append(appendstr);// append other html 
			}	
		);
}
//此方法批量将产品分配给联系人
function addPrivateProductBatch(productformid,treeid){
	var product=getAllSelectedCheckBoxValues(productformid);
	var contactperson=tree.getChecked(treeid);//此方法是TreePanel中指定属性被选中的复选框数组
	if(product.length>0&&contactperson.length>0){
	UserAction.addPrivateProductBatch(product,contactperson,function(data){hiAlert(data, '注意')});
    	}else{
		hiAlert('请至少选择一个需要分配的产品和联系人！', '注意');
	}
}



function queryPrivateProudct(firstResult,maxResults,idtoshow){
	var keyword=dwr.util.getValue("searchprivateproductkeyword");
	var id=dwr.util.getValue("privateproductcontactperson");
		UserAction.queryPrivateProduct(firstResult,maxResults,keyword,id,function(data){
		 dwr.util.setValue(idtoshow, data, { escapeHtml:false });
	} );
	
}


function queryPrivateProudctPage(){//初始化分页
	var keyword=dwr.util.getValue("searchprivateproductkeyword");
	var id=dwr.util.getValue("privateproductcontactperson");
	
	UserAction.queryPrivateProductTotalRecord(keyword,id,function(data){
	 
	$("#Pagination_privateproductmanage").pagination(data, {
		num_edge_entries: 2,
		num_display_entries: 8,
		prev_text:"上一页",
		next_text:"下一页",
		callback: queryPrivateProudctCallback
		} );
	});
	queryPrivateProudct('0','10','div_privateproductmanage_rusultcontianer');
	}

function queryPrivateProudctCallback(page_id, jq){//页码点击回调方法
	$('#Searchresult_privateproductmanage').text("当前查询结果： "+((page_id*10)+1)+"-"+((page_id*10)+10));
	queryPrivateProudct((page_id*10),'10','div_privateproductmanage_rusultcontianer');
}

//////////////////////////////
function confirmUpdatePrivateProductPrice(userId,productId,pricebox){
	hiConfirm('你确认此更新操作吗?', '注意', function(r) {
		if(r==true){
			var price=dwr.util.getValue(pricebox);
			UserAction.updatePrivateProductPrice(userId,productId,price,function(data){
				hiOverAlert(data);
			});
	 		}
	});
}

function confirmUpdatePrivateProductState(userId,productId,s){//S为更新类型 
	hiConfirm('你确认此更新操作吗?', '注意', function(r) {
		if(r==true){
				UserAction.updatePrivateProductState(userId,productId,s,function(data){
				hiOverAlert(data);
			});
	    
		}
	});
}
////////////////////////////////////////////////////////////

function showAddProductOrderParameterBatchBox(){
	hiBox('#div_message_box', '请选择产品订制参数','350','200','','.a_close');
	var content='<input type="button" value="确定" onClick="addProductOrderParameterBatch() ">';
	includePageA(gpp,'popup_message',content);
	
}

function addProductOrderParameterBatch(){
var productId=getAllSelectedCheckBoxValues('queryproductform');
var pp=getAllSelectedCheckBoxValues('productparameter');
if(pp.length>0&&productId!=0){
UserAction.addProductOrderParameterBatch(productId,pp,function(data){
	hiAlert(data, '注意');
});
}else{
	hiAlert('请至少选择一个需要指派的产品 ！', '注意');
}
}

//////////////////////////////////////////////////////////////
function showEditProductParameterBox(productId){
	hiBox('#div_message_box', '编辑产品定制参数','500','400','','.a_close');
	getProductParameterStr('popup_message',productId,'seller');
}
function getProductParameterStr(showboxid,productId,usetype){
	UserAction.getProductParameterStr(productId,usetype,
	function(data){
		 dwr.util.setValue(showboxid, data, { escapeHtml:false });
	}
	);
}
function delProductOrderParameter(id){
	UserAction.delProductOrderParameter(id,function(data){
		hiOverAlert(data);
	});
}

/////////////////////////////////////////////////////////////

function queryProcessPaymentSelectCallback(page_id, jq){
	$('#Searchresult_processpayment').text("当前查询结果： "+((page_id*10)+1)+"-"+((page_id*10)+10));
	queryProcessPayment((page_id*10),'10','queryprocesspaymentresult');
}


	function queryProcessPaymentPage(){
		var productmodel= dwr.util.getValue("processpaymentproductmodel") ;
	
		UserAction.queryProcessPaymentTotalRecord(productmodel,function(data){
		 
		$("#Pagination_processpayment").pagination(data, {
			num_edge_entries: 2,
			num_display_entries: 8,
			prev_text:"上一页",
			next_text:"下一页",
			callback: queryProcessPaymentSelectCallback
			} );
		});
		queryProcessPayment('0','10','queryprocesspaymentresult');
		}


	function queryProcessPayment(firstResult,maxResults,idtoshow){
		var productmodel= dwr.util.getValue("processpaymentproductmodel") ;
			UserAction.queryProcessPayment(firstResult,maxResults,productmodel,function(data){
			 dwr.util.setValue(idtoshow, data, { escapeHtml:false});
			
			});
		}
	
function updateProcessPayment(processpaymentid,priceabox,pricebbox,pricecbox,pricedbox,priceebox,pricefbox){
	var pricea=dwr.util.getValue(priceabox) ;
	var priceb=dwr.util.getValue(pricebbox);
	var pricec=dwr.util.getValue(pricecbox);
	var priced=dwr.util.getValue(pricedbox);
	var pricee=dwr.util.getValue(priceebox);
	var pricef=dwr.util.getValue(pricefbox);
	
	UserAction.updateProcessPayment(processpaymentid,pricea,priceb,pricec,priced,pricee,pricef,function(data){hiOverAlert(data);}
		);
	
}



////////////////////////////////////////////////////////////

function queryProductRalativeSelectCallback(page_id, jq){
	$('#Searchresult_productralative').text("当前查询结果： "+((page_id*10)+1)+"-"+((page_id*10)+10));
	queryProductRalative((page_id*10),'10','queryproductralativeresult');
}


	function queryProductRalativePage(){
		var productmodel= dwr.util.getValue("productralativeproductmodel") ;
	
		UserAction.queryProductRalativeTotalRecord(productmodel,function(data){
		 
		$("#Pagination_productralative").pagination(data, {
			num_edge_entries: 2,
			num_display_entries: 8,
			prev_text:"上一页",
			next_text:"下一页",
			callback: queryProductRalativeSelectCallback
			} );
		});
		queryProductRalative('0','10','queryproductralativeresult');
		}


	function queryProductRalative(firstResult,maxResults,idtoshow){
		var productmodel= dwr.util.getValue("productralativeproductmodel") ;
			UserAction.queryProductRalative(firstResult,maxResults,productmodel,function(data){
			 dwr.util.setValue(idtoshow, data, { escapeHtml:false});
			});
		}
	
	function delProductRalative(id){
		hiConfirm('你确认此删除操作吗?', '警告', function(r) {
			if(r==true){
				UserAction.delProductRalative(id,function(data){
					hiAlert(data);
				});
		    
			}
		});
		}
	
	function addProductRalative(){
		var productId=getRadioBoxValue('querynotralativeproductform');
		var ralativeProductId=getRadioBoxValue('qspfappform');
	if(productId!=""&&ralativeProductId!=""){
		UserAction.addProductRalative(productId,ralativeProductId,function(data){
			hiAlert(data);
		});
	
	}else{
		hiAlert("关联产品和被关联产品都是必须的！");
		}
	}

	function queryNotRalativeProductSelectCallback(page_id, jq){
		$('#Searchresult_notralativeproduct').text("当前查询结果： "+((page_id*10)+1)+"-"+((page_id*10)+10));
		queryNotRalativeProduct((page_id*10),'10','querynotralativeproductresult');
	}


		function queryNotRalativeProductPage(){
			var productmodel= dwr.util.getValue("notralativeproductmodel") ;
			UserAction.queryNotRalativeProductTotalRecord(productmodel,function(data){
			 
			$("#Pagination_notralativeproduct").pagination(data, {
				num_edge_entries: 2,
				num_display_entries: 8,
				prev_text:"上一页",
				next_text:"下一页",
				callback: queryNotRalativeProductSelectCallback
				} );
			});
			queryNotRalativeProduct('0','10','querynotralativeproductresult');
			}


		function queryNotRalativeProduct(firstResult,maxResults,idtoshow){
			var productmodel= dwr.util.getValue("notralativeproductmodel") ;
				UserAction.queryNotRalativeProduct(firstResult,maxResults,productmodel,function(data){
				 dwr.util.setValue(idtoshow, data, { escapeHtml:false});
				});
			}
		
	
		
		
	/////////////////////////////////////////////////////////////
		
		function querySellerProductForAddProductRalativeCallback(page_id, jq){
			$('#Searchresult_querysellerproduct').text("当前查询结果： "+((page_id*10)+1)+"-"+((page_id*10)+10));
			querySellerProductForAddProductRalative((page_id*10),'10','querysellerproductresult');
		}

		
		function querySellerProductForAddProductRalativePage(){
			var productkeyword= dwr.util.getValue("searchproductkeyword") ;
			var contactperson= dwr.util.getValue("contactpersonforquerysellerproduct");
			UserAction.querySellerProductForAddProductRalativeTotalRecord(productkeyword,contactperson,function(data){
			 
			$("#Pagination_querysellerproduct").pagination(data, {
				num_edge_entries: 2,
				num_display_entries: 8,
				prev_text:"上一页",
				next_text:"下一页",
				callback: querySellerProductForAddProductRalativeCallback
				} );
			});
			querySellerProductForAddProductRalative('0','10','querysellerproductresult');
			}


		function querySellerProductForAddProductRalative(firstResult,maxResults,idtoshow){
			var productkeyword= dwr.util.getValue("sellerproductkeyword") ;
			var contactperson= dwr.util.getValue("contactpersonforquerysellerproduct");
			UserAction.querySellerProductForAddProductRalative(firstResult,maxResults,productkeyword,contactperson,function(data){
				 dwr.util.setValue(idtoshow, data, { escapeHtml:false });
				
				});
			}
		

////////////////////////////////////////////////////////////////////
		function queryOrderForSellerCallback(page_id, jq){
			$('#Searchresult_queryorderforseller').text("当前查询结果： "+((page_id*10)+1)+"-"+((page_id*10)+10));
			queryOrderForSeller((page_id*10),'10','div_queryorderforseller_rusultcontianer');
		}


			function queryOrderForSellerPage(){
				var orderid= dwr.util.getValue("sellerordermanage_orderid") ;
				var modelorname= dwr.util.getValue("sellerordermanage_productmodelorname");
				var orderstartdate= dwr.util.getValue("sellerordermanage_orderstartdate");
				var orderenddate= dwr.util.getValue("sellerordermanage_orderenddate");
				var seller= dwr.util.getValue("sellerordermanage_seller");
				var orderstate= dwr.util.getValue("sellerordermanage_orderstate");
				if(orderid==""){
					orderid="0";
				}
				if(orderstate==""){
					orderstate="0";
				}
				if(seller==""){
					seller="0";
				}
				
				UserAction.queryOrderForSellerTotalRecord(orderid,modelorname,orderstartdate, orderenddate,seller,orderstate,function(data){
				 
				$("#Pagination_queryorderforseller").pagination(data, {
					num_edge_entries: 2,
					num_display_entries: 8,
					prev_text:"上一页",
					next_text:"下一页",
					callback: queryOrderForSellerCallback
					} );
				});
				queryOrderForSeller('0','10','div_queryorderforseller_rusultcontianer');
				}


			function queryOrderForSeller(firstResult,maxResults,idtoshow){
				var orderid= dwr.util.getValue("sellerordermanage_orderid") ;
				var modelorname= dwr.util.getValue("sellerordermanage_productmodelorname");
				var orderstartdate= dwr.util.getValue("sellerordermanage_orderstartdate");
				var orderenddate= dwr.util.getValue("sellerordermanage_orderenddate");
				var seller= dwr.util.getValue("sellerordermanage_seller");
				var orderstate= dwr.util.getValue("sellerordermanage_orderstate");
					if(orderid==""){
					orderid="0";
				}
				if(orderstate==""){
					orderstate="0";
				}
				if(seller==""){
					seller="0";
				}
		   			UserAction.queryOrderForSeller(firstResult,maxResults,orderid,modelorname,orderstartdate, orderenddate,seller,orderstate,function(data){
					 dwr.util.setValue(idtoshow, data, { escapeHtml:false });
					 initHighslide();
					});
				}
			

			function summaryOrderForSeller(idtoshow){
				var modelorname= dwr.util.getValue("sellerordersummary_productmodelorname");
				var orderstartdate= dwr.util.getValue("sellerordersummary_orderstartdate");
				var orderenddate= dwr.util.getValue("sellerordersummary_orderenddate");
				var seller= dwr.util.getValue("sellerordersummary_seller");
				var orderstate= dwr.util.getValue("sellerordersummary_orderstate");
			
				if(orderstate==""){
					orderstate="0";
				}
				if(seller==""){
					seller="0";
				}
		   			UserAction.summaryOrderForSeller(modelorname,orderstartdate, orderenddate,seller,orderstate,function(data){
					 dwr.util.setValue(idtoshow, data, { escapeHtml:false });
					
					});
				}
		
///////////////////////////////////////////////////////////////////
			function prePrintObject(dataFromForm,printType,prePrintPage){
				//dataFrom 从哪里得到需要打印的数组displayPage打印页面,dataSessionIndex需打印的数据索引sessionIndex会话
				var printdata=getAllSelectedCheckBoxValues(dataFromForm);
				if(printdata.length>0){
					UserAction.prePrintObject(printdata,printType,function(data){if(data==true){
					window.open(prePrintPage,"_blank","width=800,height=600,scrollbars=yes");	
							
					}});
				}else{
					hiAlert("请至少选择一个要打印的订单！");
				}
				
				
			}
			
///////////////////////////////////////////////////////////////////			
			
